#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<omp.h>


void hello(void) {
    //返回线程号
	int my_rank = omp_get_thread_num();
    //返回当前并行区域中的线程数
	int thread_count = omp_get_num_threads();
	printf("Hello from thread %d of %d. \n", my_rank, thread_count);
}

int main(int argc, char** argv) {
	int thread_count = strtol(argv[1],NULL,10);
	
//num_threads指定要用多少个线程来实现hello
#pragma omp parallel num_threads(thread_count)
{
    #pragma omp single nowait
    {
        int nthreads = omp_get_num_threads();
        sleep(5);
        printf("number of threads = %d\n",nthreads);
    }
	hello();
}
	return 0;
}
